/**
* @Description: 租户管理
* @author  tangbin
* @date 2023/3/8
*/

 <template>
  <div class="app-container" style="background-color: #fff;">
    <div class="page-search-wrap" id="searchForm">
      <el-form class="page-search-wrap-form" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
        <el-form-item label="公司名" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入公司名"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="账号" prop="account">
          <el-input
            v-model="queryParams.account"
            placeholder="请输入账号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="有效期" prop="expireTime">
          <el-date-picker
            clearable
            size="small"
            v-model="queryParams.expireTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期" />
        </el-form-item>
        <el-form-item label="是否激活" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择是否激活" clearable size="small">
          <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="所属租户级别" prop="level">
          <el-select
            size="small"
            v-model="queryParams.level"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="dict in dict.type.sys_tenant_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
      <el-form-item label="权限模板" prop="templateName">
          <el-input
            v-model="queryParams.templateName"
            placeholder="请输入模板名"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      </el-form>
    </div>

    <div class="com-tabel" id="comTabel">
      <div class="bg-line"></div>
      <div class="m-t-search clearfix">
        <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['system:tenant:add']"
          >新增</el-button>
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:tenant:edit']"
          >修改</el-button>
        </el-col> -->
        <!-- <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:tenant:export']"
          >导出</el-button>
        </el-col> -->
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      </div>
    </div>

    <div class="page-table">
      <el-table
        v-loading="loading" 
        :data="dataList" 
        @selection-change="handleSelectionChange"
        ref="filterTable"
        :style="{height: height + 'px', minHeight: 200 + 'px'}"
        :height="height"
      >
        <!-- <el-table-column type="selection" width="55" align="center"/> -->
        <el-table-column label="公司名" align="center" prop="name" show-overflow-tooltip min-width="200"/>
        <el-table-column label="账号" align="center" prop="account" show-overflow-tooltip min-width="160"/>
        <el-table-column label="邮箱" align="center" prop="email" show-overflow-tooltip min-width="240" />
        <el-table-column label="信用代码" align="center" prop="creditCode" show-overflow-tooltip min-width="220" />
        <el-table-column label="租户类型" align="center" prop="type" show-overflow-tooltip min-width="140">
          <template slot-scope="scope">
            <span>{{getType(scope.row.type)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="关联客户/供应商" align="center" prop="customerName" show-overflow-tooltip min-width="180" :formatter="(row) => row.customerName.toString()">
          <template slot-scope="scope">
            <span>{{scope.row.customerName&&scope.row.customerName.length != 0?scope.row.customerName.toString():scope.row.supplierName.toString()}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="关联供应商" align="center" prop="supplierName" show-overflow-tooltip min-width="180" :formatter="(row) => row.supplierName.toString()" /> -->
        <!-- customerName -->
        <el-table-column label="有效期限" align="center" prop="expireTime" min-width="140">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.expireTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="是否激活" align="center" prop="status" :formatter="activeFlagFormat" min-width="90" />
        <el-table-column label="是否测试" align="center" prop="isTest" :formatter="testFlagFormat" min-width="90" />
        <!-- 租户层级（0智科 1一级租户2 二级租户） -->
        <el-table-column label="所属租户级别" align="center" prop="level" :formatter="levelFormat" min-width="120" />
        <el-table-column label="所属上级租户" align="center" prop="parentName" show-overflow-tooltip min-width="127" />
        <el-table-column label="权限模板" align="center" prop="templateName" show-overflow-tooltip min-width="180" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="140">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="180">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:tenant:edit']"
            >修改
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-key"
              @click="handleResetPwd(scope.row)"
              v-hasPermi="['system:tenant:resetPwd']"
            >重置密码
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>


    <!-- 添加或修改公司信息对话框(新) -->
    <el-dialog :title="title" :visible.sync="open" width="995px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <!-- 所属租户级别 上级租户 -->
        <el-row>
          <el-col :span="24">
            <el-form-item label="租户类型:" prop="type">
              <el-radio-group v-model="form.type" @input="changeType" :disabled="!isAdd">
                <el-radio label="CUSTOMER">客户</el-radio>
                <el-radio label="SUPPLIER">供应商</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.type == 'CUSTOMER'">
            <el-form-item label="所属租户级别:" prop="level">
              <el-select size="small" v-model="form.level" placeholder="请选择" style="width: 100%" @change="changeTenantLevel" :disabled="!isAdd">
                <el-option v-for="dict in tenantLevels" :key="dict.value" :label="dict.label" :value="dict.value" :disabled="dict.disabled"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-else>
            <el-form-item label="所属租户级别:" prop="level">
              <!-- <el-input v-model.trim="form.level" placeholder="一级租户" size="small" disabled /> -->
              <el-select size="small" v-model="form.level" placeholder="请选择" style="width: 100%" disabled>
                <el-option v-for="dict in tenantLevels" :key="dict.value" :label="dict.label" :value="dict.value" :disabled="dict.disabled"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.type == 'CUSTOMER'">
            <el-form-item label="上级租户:" prop="parentId" v-show="isShowPresent">
              <el-select size="small" v-model="form.parentId" placeholder="请选择" style="width: 100%" :disabled="!isAdd" filterable>
                <el-option v-for="dict in parentTenants" :key="dict.id" :label="dict.name" :value="dict.id"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-else>
            <el-form-item label="上级租户:" prop="parentId" v-show="isShowPresent">
              <!-- <el-input v-model.trim="form.parentId" placeholder="潍柴智能科技有限公司" size="small" disabled /> -->
              <el-select size="small" v-model="form.parentId" placeholder="请选择" style="width: 100%" disabled filterable>
                <el-option v-for="dict in parentTenants" :key="dict.id" :label="dict.name" :value="dict.id"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 关联客户 公司名称 -->
        <el-row>
          <el-col :span="12" v-if="form.type == 'CUSTOMER'">
            <el-form-item label="关联客户:" prop="customName">
              <el-input v-model.trim="form.customName" placeholder="请选择关联客户" size="small" disabled maxlength="200">
                <a slot="suffix" class="link" @click="selectCustomer">配置关联客户</a>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-else>
            <el-form-item label="关联供应商:" prop="supplierName">
              <el-input v-model.trim="form.supplierName" placeholder="请选择关联供应商" size="small" disabled maxlength="200">
                <a slot="suffix" class="link" @click="selectSupplier">配置关联供应商</a>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司名:" prop="name">
              <el-input v-model.trim="form.name" placeholder="请输入公司名" size="small" maxlength="200" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 地址 账号 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="地址:" prop="areaValue">
              <el-cascader size="small" style="width:100%" v-model="form.areaValue"
                :options="areaList" :props="propsArea" clearable
                @change="handleChangeArea"></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="账号:" prop="account">
              <el-input v-model.trim="form.account" placeholder="默认为管理员账号的电话" size="small" maxlength="50" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 详情地址 邮箱 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="" prop="address">
            <el-input type="textarea" v-model.trim="form.address" placeholder="请输入详细地址" maxlength="200" show-word-limit />
          </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮箱:" prop="email">
            <el-input v-model.trim="form.email" placeholder="请输入邮箱" size="small" maxlength="50" clearable/>
          </el-form-item>
          </el-col>
        </el-row>
        <!-- 信用代码 有效期限 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="信用代码:" prop="creditCode">
            <el-input size="small" v-model.trim="form.creditCode" maxlength="18" @input="form.creditCode = form.creditCode.replace(/[^A-Z0-9]/g, '')" placeholder="请输入信用代码" clearable/>
          </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="有效期限:" prop="expireTime">
              <el-date-picker clearable size="small" style="width: 100%"
                v-model="form.expireTime"
                type="date"
                value-format="yyyy-MM-dd"
                :picker-options="pickerOptionTime"
                placeholder="选择有效期限">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 是否激活 是否测试 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否激活:">
              <el-radio-group v-model="form.status">
                <el-radio :key="1" :label="1">激活</el-radio>
                <el-radio :key="0" :label="0">禁用</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否测试:">
              <el-radio-group v-model="form.isTest">
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="权限模板:" prop="templateId">
              <el-select size="small" v-model="form.templateId" filterable placeholder="请选择模板" 
                clearable style="width: 100%" :disabled="!isAdd"
              >
                <el-option v-for="item in this.templateList" :key="item.id" :label="item.name" :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>


      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm" :loading="saveloading">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改公司信息对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="505px" append-to-body :close-on-click-modal="false">
      <div class="clearfix">
        <el-button type="text" class="customer-config" @click="selectCustomer">配置关联客户</el-button>
      </div>
      
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="公司名" prop="name">
          <el-input v-model.trim="form.name" placeholder="请输入公司名" size="small" maxlength="200" clearable />
        </el-form-item>
        <el-form-item label="地址" prop="areaValue">
          <el-cascader
            size="small"
            style="width:100%"  
            v-model="form.areaValue"
            :options="areaList"
            :props="propsArea"
            clearable
            @change="handleChangeArea"></el-cascader>
        </el-form-item>
        <el-form-item label="" prop="address">
          <el-input type="textarea" v-model.trim="form.address" placeholder="请输入详细地址" maxlength="200" show-word-limit />
        </el-form-item>
        <el-form-item label="账号" prop="account">
          <el-input v-model.trim="form.account" placeholder="默认为管理员账号的电话" size="small" maxlength="50" clearable/>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model.trim="form.email" placeholder="请输入邮箱" size="small" maxlength="50" clearable/>
        </el-form-item>
        <el-form-item label="信用代码" prop="creditCode">
          <el-input size="small" v-model.trim="form.creditCode" maxlength="18" @input="form.creditCode = form.creditCode.replace(/[^A-Z0-9]/g, '')" placeholder="请输入信用代码" clearable/>
        </el-form-item>
        <el-form-item label="有效期限" prop="expireTime">
          <el-date-picker clearable size="small" style="width: 100%"
            v-model="form.expireTime"
            type="date"
            value-format="yyyy-MM-dd"
            :picker-options="pickerOptionTime"
            placeholder="选择有效期限">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否激活">
          <el-radio-group v-model="form.status">
            <el-radio :key="1" :label="1">激活</el-radio>
            <el-radio :key="0" :label="0">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否测试">
          <el-radio-group v-model="form.isTest">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="所属租户级别" prop="level">
          <el-select size="small" v-model="form.level" placeholder="请选择" clearable style="width: 100%" @change="changeTenantLevel" :disabled="!isAdd">
            <el-option v-for="dict in tenantLevels" :key="dict.value" :label="dict.label" :value="dict.value" :disabled="dict.disabled"/>
          </el-select>
        </el-form-item>
        <el-form-item label="上级租户" prop="parentId" v-show="isShowPresent">
          <el-select size="small" v-model="form.parentId" placeholder="请选择" clearable style="width: 100%" :disabled="!isAdd">
            <el-option v-for="dict in parentTenants" :key="dict.id" :label="dict.name" :value="dict.id"/>
          </el-select>
        </el-form-item>
        <el-form-item label="权限模板" prop="templateId">
          <el-select size="small" v-model="form.templateId" filterable placeholder="请选择模板" 
            clearable style="width: 100%" :disabled="!isAdd"
          >
            <el-option v-for="item in this.templateList" :key="item.id" :label="item.name" :value="item.id"/>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="saveloading">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->

    <!-- 关联客户 -->
    <el-dialog title="关联客户" :visible.sync="showCustomer" width="720px" append-to-body :close-on-click-modal="false">
        <div class="dialog-main">
          <div class="dialog-left">
            <el-form :inline="true">
              <el-form-item label="客户名称:">
                <el-input
                  placeholder="请输入"
                  clearable
                  v-model="filterText"
                  size="small"
                >
                </el-input>
              </el-form-item>
              <el-form-item label="" style="margin-bottom: 0;">
                <!-- @node-click="nodeClick" -->
                <div class="left-area">
                  <el-tree
                    :data="customers"
                    show-checkbox
                    ref="menu"
                    node-key="id"
                    :check-strictly="false"
                    empty-text="暂无数据"
                    :props="defaultProps"
                    @check="treeCheck"
                    :filter-node-method="filterNodeArea"
                    :check-on-click-node="true"
                  ></el-tree>
                </div>
              </el-form-item>
            </el-form>
          </div>
          <div class="dialog-right">
            <span class="right-top">已选择客户</span>
            <el-table
              class="right-bottom"
              :data="checkedCustomers" 
              :inline="true"
              :border="false"
            >
              <el-table-column label="" align="left" prop="name" width="340px">
                <template slot-scope="scope">
                  <div class="table-column-area">
                    <span class="table-column-area-span">{{ scope.row.comName }}</span>
                    <el-button class="table-column-area-btn" size="mini" type="text" icon="el-icon-circle-close" @click="deleteCanPrice(scope.row)"></el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancelDialog">取 消</el-button>
          <el-button type="primary" @click="submitCustomer" :loading="btnLoad">确 定</el-button>
        </div>
    </el-dialog>

    <!-- 关联供应商 -->
    <el-dialog title="关联供应商" :visible.sync="showSupplier" width="720px" append-to-body :close-on-click-modal="false">
        <div class="dialog-main">
          <div class="dialog-left">
            <el-form :inline="true">
              <el-form-item label="供应商名称:">
                <el-input
                  placeholder="请输入"
                  clearable
                  v-model="supplierText"
                  size="small"
                >
                </el-input>
              </el-form-item>
              <el-form-item label="" style="margin-bottom: 0;">
                <!-- @node-click="supplierNodeClick" -->
                <div class="left-area">
                  <el-tree
                    :data="suppliers"
                    show-checkbox
                    ref="menus"
                    node-key="id"
                    :check-strictly="false"
                    empty-text="暂无数据"
                    :props="defaultProps"
                    @check="supplierTreeCheck"
                    :filter-node-method="filterNodeArea"
                    :check-on-click-node="true"
                  ></el-tree>
                </div>
              </el-form-item>
            </el-form>
          </div>
          <div class="dialog-right">
            <span class="right-top">已选择供应商</span>
            <el-table
              class="right-bottom"
              :data="checkedSuppliers" 
              :inline="true"
              :border="false"
            >
              <el-table-column label="" align="left" prop="name" width="340px">
                <template slot-scope="scope">
                  <div class="table-column-area">
                    <span class="table-column-area-span">{{ scope.row.comName }}</span>
                    <el-button class="table-column-area-btn" size="mini" type="text" icon="el-icon-circle-close" @click="deleteSupplier(scope.row)"></el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancelSupDialog">取 消</el-button>
          <el-button type="primary" @click="submitSupplier" :loading="btnLoad">确 定</el-button>
        </div>
    </el-dialog>

  </div>
</template>

<script>
import { validEmail, validPhone } from "@/utils/validate";
import {getDivisionTree} from '@/api/basic/orderGoodsClas.js'
import {listTenant, addTenant, updateTenant, exportTenant, parentListTenant, resetPwdTenant, customerOptionSelect, correlationCustomers, supplierOptionSelect, supplierList} from '@/api/system/tenant.js';
import {tenantTemplateOptions} from '@/api/system/permission.js'
export default {
  name: 'Tenant',
  dicts: ['sys_tenant_level', 'basic_data_customer_type', 'tenant_type'],
  data() {
    return {
      pickerOptionTime: {
         disabledDate: this.disabledDates,
      }, // 对有效期 日期 做限制

      // customerValue: [], //  客户数据
      // customerData: [],

      height: 200,
      saveloading: false,
      // disabled: false,

      btnLoad: false, // 点击确认按钮后 旋转轮
      showCustomer: false, // 是否显示关联客户
      showSupplier:false, // 是否显示关联供应商
      filterText: '', // 搜索客户
      supplierText: '', // 搜索供应商
      defaultProps: {children: "children", label: "comName"},

      isAdd: true, // 是否新增

      isShowPresent: true, // 是否显示上级租户

      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dataList: [],
      propsArea: {label: 'name', value: 'id', children: 'children', checkStrictly: true},
      areaList:[], // 省市区
      tenantLevels:[], // 租户级别
      templateList:[], // 模板权限
      parentTenants:[], // 上级用户
      customers: [], // 客户列表
      checkedCustomers: [], // 选中的客户列表
      suppliers: [], // 供应商列表
      checkedSuppliers: [], // 选中的供应商列表
      title: '', // 弹窗标题
      // 是否显示弹出层
      open: false,
      // 总条数
      total: 0,
      // 激活状态
      statusList: [
        {label:'停用', value: 0},
        {label: '正常', value: 1}
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined, // 公司名
        account: undefined, // 账号
        expireTime: undefined, // 有效期
        status: undefined, // 是否激活
        level: undefined, // 所属层级
        templateName: undefined, // 全县模板
      },
      form: {},
      rules: {}
    }
  },

  created() {
    this.setupRules();
    this.handleQuery();
    // this.parentListTenant();
  },
  mounted() {
    // this.setupTenantLevels();
    this.getDivisionTree(); // 地区
    // this.getCustomerOptionSelect(); // 客户信息
    this.reset();
  },
  activated() {
    this.tableHeight();
  },
  updated() {
    // 解决表格设置固定高度导致列设置fixed后重新进来会错行问题
    this.tableHeight();
    this.$nextTick(() => {
      this.$refs.filterTable.doLayout();
    });
  },
  watch: {
    filterText(val) {
      // console.log('val=', val);
      this.$refs.menu.filter(val);
    },
    supplierText(val) {
      // console.log('val=', val);
      this.$refs.menus.filter(val);
    }
  },

  methods: {
    
    /** 租户类型 */
    getType(row) {
      let show = '';
      this.dict.type.tenant_type.some((item) => {
        if (item.value === row) {
          show = item.label;
          return true;
        }
      });
      return show;
    },
    /**
     * 重置表单
     */
    reset() {
      // 370000,370100,370102
      this.form = {
        type: 'CUSTOMER', // 租户类型
        customIds:[], // 关联客户id
        customName: undefined, // 关联客户名称
        supplierIds:[], // 关联供应商id
        supplierName:undefined, // 关联供应商名称
        id: undefined,
        name: undefined, // 租户名称
        areaValue: [], // 区域数组
        provinceCode: undefined, // 省份编码
        cityCode: undefined, // 城市编码
        districtCode: undefined, // 区县编码
        address: undefined, // 详细地址
        account: undefined, // 账号
        email: undefined, // 邮箱
        creditCode: undefined, // 信用代码
        expireTime: undefined, // 有效期
        status: 1, // 是否激活
        isTest: 0, // 是否测试
        level: undefined, // 租户层级（0智科 1一级租户2 二级租户）
        parentId: undefined, // 上级租户
        templateId: undefined, // 权限模板
      };
      this.resetForm("form");
    },

    tableHeight() {
      this.$nextTick(() => {
        let height = document.body.clientHeight - 90 - 40;
        // 查询表单高度
        let s_height = document.getElementById('searchForm').clientHeight;
        // 按钮容器高度
        let btns_height = document.getElementById('comTabel').clientHeight;
        // 计算表格的高度
        this.height = height - s_height - btns_height - (this.total > 0 ? 60 : 0);
      });
    },

    setupRules() {

      // 验证邮箱地址
      const validateEmail = (rule, value, callback) => {
        // if (!value || value.length == 0) {
        //   callback(new Error("请输入邮箱地址"));
        // } 
        if (value && value.length > 8 && !validEmail(value)) {
          callback(new Error("请输入正确格式的邮箱地址"));
        } else {
          callback();
        }
      }

      // 名称
      const validateName = (rule, value, callback) => {
        if (!value || value.length == 0) {
          callback(new Error("公司名不能为空"));
        } else if (value && value.length > 200) {
          callback(new Error("名称长度不能超过200个字符"));
        } else {
          callback();
        }
      }

      // 账号
      const validateAccount = (rule, value, callback) => {
        if (!value || value.length == 0) {
          callback(new Error("账号不能为空"));
        } else if (value && value.length > 50) {
          callback(new Error("账号长度不能超过50个字符"));
        } else {
          callback();
        }
      }

      this.rules = {
        name: [
          {required: true, validator: validateName, trigger: "blur"}
        ],
        account: [
          {required: true, validator: validateAccount, trigger: "blur"}
        ],
        email: [
          {required: false, validator: validateEmail, trigger: "blur"}
        ],
        expireTime: [
          {required: true, message: "有效期限不能为空", trigger: "blur"}
        ],
        level: [
          {required: true, message: "请选择所属租户级别", trigger: "change"}
        ],
        parentId: [
          {required: true, message: "请选择上级租户", trigger: "change"}
        ],
        templateId: [
          {required: true, message: "请选择权限模板", trigger: "change"}
        ],
        areaValue: [
          // {type:'array', required: true, message: "请选择地址", trigger: "change"}
          {required: true, message: "请选择地址", trigger: "change"}
        ],
      };
    },
    /** 租户类型change */
    changeType(val) {
      console.log(val)
      if(val == 'SUPPLIER'){
        this.form.level = '1';
        this.tenantTemplateOptions();
        this.parentListTenant()
        this.form.parentId = '0';
      }else{
        this.form.level = undefined;
        this.form.parentId = undefined;
      }
    },
    /**
     * 获取客户信息
     */
    getCustomerOptionSelect() {
      // console.log('eeeeee=', this.form);
      let param = {};
      if (this.form.level == '2') { // 租户级别为 2 的时候
        param = {level: this.form.level, tenantId: this.form.parentId};
      }
      // console.log('param=', param);
      customerOptionSelect(param).then(res => {
        // console.log('res====', res);
        this.customers = [];
        if (res.code === 200) {
          let list = res.data;
          list.forEach((item) => {
            item.disabled = item.associated;
            item.comName = item.code + '-' + item.name + '-' + this.filterCustomerType(item.type);
            this.customers.push(item);
          });
        }

      }).catch(err => {

      });
    },

    /**
     * 获取关联客户列表
     */
    correlationCustomers() {
      let params = {
        tenantId: this.form.id
      }
      correlationCustomers(params).then(res => {
        // console.log('获取关联客户=', res);
        if (res.code === 200) {
          let list = res.data;
          list.forEach((item) => {
            this.form.customIds.push(item.customerId);
          });
        }
      }).catch(err => {

      });
    },

    /**
     * 获取供应商信息
     */
    getSupplierSelect() {
      supplierOptionSelect().then(res => {
        console.log('res====', res);
        this.suppliers = [];
        if (res.code === 200) {
          let list = res.data;
          list.forEach((item) => {
            item.disabled = item.associated;
            item.comName = item.code + '-' + item.name;
            this.suppliers.push(item);
          });
        }

      }).catch(err => {

      });
    },

    /**
     * 获取关联供应商列表
     */
    supplierList() {
      let params = {
        tenantId: this.form.id
      }
      supplierList(params).then(res => {
        // console.log('获取关联供应商=', res);
        if (res.code === 200) {
          let list = res.data;
          list.forEach((item) => {
            this.form.supplierIds.push(item.supplierId);
          });
        }
      }).catch(err => {

      });
    },

    /**
     * 根据客户类型 查找类型名称
     * @param {*} type 
     */
    filterCustomerType(type) {
      // console.log('type=', type);
      let typeName = '';
      this.dict.type.basic_data_customer_type.some((item) => {
        // console.log('item=', item.value);
        if (item.value == type) {
          // console.log('有相同的');
          typeName = item.label;
          return true;
        }
      });
      return typeName;
    },

    /**
     * 过滤属性结构的数据
     * @param {*} value 
     * @param {*} data 
     */
     filterNodeArea(value, data) {
      // console.log('value=', value);
      if (!value) {
        return true;
      }
      return data.comName.indexOf(value) !== -1;
    },

    /**
     * 从列表中删除 删除可用价格
     * @param {*} row 
     */
     deleteCanPrice(row) {
      // console.log('row=', row);
      this.checkedCustomers.splice(this.checkedCustomers.indexOf(row), 1);
      this.customers.some((item) => {
        if (item.id == row.id) {
          item.disabled = false;
          return true;
        }
      });
      this.$nextTick(()=>{
        this.$refs.menu.setChecked(row.id, false ,false);
      });
    },

    /**
     * 从列表中删除 删除可用供应商
     * @param {*} row 
     */
     deleteSupplier(row) {
      // console.log('row=', row);
      this.checkedSuppliers.splice(this.checkedSuppliers.indexOf(row), 1);
      this.suppliers.some((item) => {
        if (item.id == row.id) {
          item.disabled = false;
          return true;
        }
      });
      this.$nextTick(()=>{
        this.$refs.menus.setChecked(row.id, false ,false);
      });
    },

    /** 
     * 点击节点 客户
     * @param {*} item 
     * @param {*} node 
     * @param {*} v3 
     */
    nodeClick(item, node, v3) {
      let checked = !node.checked;
      this.$refs.menu.setCheckedKeys([]);
      // node.checked = !node.checked;
      if (checked == true) { // 选中
        node.checked = checked;
        this.checkedCustomers.splice(0,this.checkedCustomers.length);
        this.checkedCustomers.push(item);
        // if (this.checkedCustomers.length > 1) {
        //   this.$modal.msg('一个租户只能关联一个客户！');
        // }
      } else { // 未选中
        node.checked = checked;
        this.checkedCustomers.splice(0,this.checkedCustomers.length);
        // this.checkedCustomers.splice(this.checkedCustomers.indexOf(item), 1);
      }
    },

    /**
     * 点击节点 供应商
     * @param {*} item 
     * @param {*} node 
     * @param {*} v3 
     */
    supplierNodeClick(item, node, v3) {
      let checked = !node.checked;
      this.$refs.menus.setCheckedKeys([]);
      // node.checked = !node.checked;
      if (checked == true) { // 选中
        node.checked = checked;
        this.checkedSuppliers.splice(0,this.checkedSuppliers.length);
        this.checkedSuppliers.push(item);
        // if (this.checkedSuppliers.length > 1) {
        //   this.$modal.msg('一个租户只能关联一个客户！');
        // }
      } else { // 未选中
        node.checked = checked;
        this.checkedSuppliers.splice(0,this.checkedSuppliers.length);
        // this.checkedSuppliers.splice(this.checkedSuppliers.indexOf(item), 1);
      }
    },

    /**
     * 点击tree 勾选 取消勾选 客户
     * @param {*} item 
     * @param {*} de 
     */
     treeCheck(item, data) {
      if (data.checkedKeys.indexOf(item.id) !== -1) { // 选中
        this.$refs.menu.setCheckedKeys([]);
        this.$refs.menu.setChecked(item.id, true ,false);
        this.checkedCustomers.splice(0,this.checkedCustomers.length);
        this.checkedCustomers.push(item);
        // if (this.checkedCustomers.length > 1) {
        //   this.$modal.msg('一个租户只能关联一个客户！');
        // }
      } else { // 未选中
        this.$refs.menu.setCheckedKeys([]);
        // this.checkedCustomers.splice(this.checkedCustomers.indexOf(item), 1);
        this.checkedCustomers.splice(0,this.checkedCustomers.length);
      }
     },
     
    /**
     * 点击tree 勾选 取消勾选 供应商
     * @param {*} item 
     * @param {*} de 
     */
     supplierTreeCheck(item, data) {
      console.log(item, data)
      if (data.checkedKeys.indexOf(item.id) !== -1) { // 选中
        this.$refs.menus.setCheckedKeys([]);
        this.$refs.menus.setChecked(item.id, true ,false);
        this.checkedSuppliers.splice(0,this.checkedSuppliers.length);
        this.checkedSuppliers.push(item);
        // if (this.checkedSuppliers.length > 1) {
        //   this.$modal.msg('一个租户只能关联一个客户！');
        // }
      } else { // 未选中
        this.$refs.menus.setCheckedKeys([]);
        // this.checkedSuppliers.splice(this.checkedSuppliers.indexOf(item), 1);
        this.checkedSuppliers.splice(0,this.checkedSuppliers.length);
      }
     },

     /**
     * 选择关联客户 -- 显示关联客户弹窗 点击配置关联客户按钮
     */
    selectCustomer() {

      // console.log('level=', this.form.level);
      // console.log('parentId=', this.form.parentId);
      if (this.form.level == undefined || (this.form.level && this.form.level.length == 0)) {
        this.$modal.msgWarning('请先选择租户级别！');
        return;
      }
      if (this.form.parentId == undefined || (this.form.parentId && this.form.level.parentId == 0)) {
        this.$modal.msgWarning('请先选择上级租户！');
        return;
      }

      this.getCustomerOptionSelect(); // 客户信息
      this.showCustomer = true; 
      this.btnLoad = false;
      this.checkedCustomers = [];
      this.filterText = "";
      this.$nextTick(()=>{
        this.$refs.menu.setCheckedKeys([]);
        if (this.form.customIds && this.form.customIds.length > 0) {
          this.form.customIds.forEach((id) => {
            // console.log('id=', id);
            this.customers.some((model) => {
              // console.log('mid=', model.id, '; id=', id);
              if (model.id === id) {
                model.disabled = false;
                this.checkedCustomers.push(model);
                this.$refs.menu.setChecked(model.id, true ,false);
                return true;
              }
            });
          });
        }
      });
      
    },

     /**
      * 选择关联客户 点击确认
      */
     submitCustomer() {

      if (this.checkedCustomers.length > 1) {
        this.$modal.msg('一个租户只能关联一个客户！');
        return;
      }

      console.log('checkedCustomers=', this.checkedCustomers);

      this.btnLoad = true;
      this.form.customIds = [];

      if (this.checkedCustomers && this.checkedCustomers.length == 0) {
        this.form.customName = undefined;
        this.form.name = undefined; // 租户名称
        this.form.areaValue = []; // 区域数组
        this.form.provinceCode = undefined; // 省份编码
        this.form.cityCode = undefined; // 城市编码
        this.form.districtCode = undefined; // 区县编码
        this.form.address = undefined; // 详细地址
        // account: undefined, // 账号
        this.form.email = undefined; // 邮箱
        this.form.creditCode = undefined; // 信用代码
        this.cancelDialog();
        return;
      }

      this.checkedCustomers.forEach((item) => {
        // console.log('item=', item);
        this.form.customName = item.name;
        this.form.customIds.push(item.id);

        
        this.form.name = item.name; // 租户名称
        this.form.areaValue = []; // 区域数组
        if (item.districtCode && item.districtCode.length > 0) {
          this.form.areaValue = [item.provinceCode, item.cityCode, item.districtCode];
        } else if (item.cityCode && item.cityCode.length > 0) {
          this.form.areaValue = [item.provinceCode, item.cityCode];
        } else if (item.provinceCode && item.provinceCode.length > 0) {
          this.form.areaValue = [item.provinceCode];
        }
        this.form.provinceCode = item.provinceCode; // 省份编码
        this.form.cityCode = item.cityCode; // 城市编码
        this.form.districtCode = item.districtCode; // 区县编码
        this.form.address = item.address; // 详细地址
        // account: undefined, // 账号
        this.form.email = item.email; // 邮箱
        this.form.creditCode = item.creditCode; // 信用代码
      });
      this.cancelDialog();
     },

     /**
      * 选择关联客户 点击取消
      */
     cancelDialog() {
      this.showCustomer = false;
      this.checkedCustomers = [];
      // this.btnLoad = false;
      // this.$nextTick(() => {
      //   this.$refs.menu.setCheckedKeys([]);
      // });
     },

     /**
     * 选择关联供应商 -- 显示关联供应商弹窗 点击配置关联供应商按钮
     */
     selectSupplier() {

      this.getSupplierSelect(); // 供应商信息
      this.showSupplier = true; 
      this.btnLoad = false;
      this.checkedSuppliers = [];
      this.supplierText = "";
      this.$nextTick(()=>{
        this.$refs.menus.setCheckedKeys([]);
        if (this.form.supplierIds && this.form.supplierIds.length > 0) {
          this.form.supplierIds.forEach((id) => {
            console.log('id=', id, this.suppliers);
            this.suppliers.some((model) => {
              console.log('mid=', model.id, '; id=', id);
              if (model.id === id) {
                model.disabled = false;
                this.checkedSuppliers.push(model);
                this.$refs.menus.setChecked(model.id, true ,false);
                return true;
              }
            });
          });
        }
      });

     },
     /**
      * 选择关联供应商 点击确认
      */
     submitSupplier() {

      this.btnLoad = true;
      this.form.supplierIds = [];

      if (this.checkedSuppliers && this.checkedSuppliers.length == 0) {
        this.form.supplierName = undefined;
        this.form.name = undefined; // 租户名称
        this.form.areaValue = []; // 区域数组
        this.form.provinceCode = undefined; // 省份编码
        this.form.cityCode = undefined; // 城市编码
        this.form.districtCode = undefined; // 区县编码
        this.form.address = undefined; // 详细地址
        // account: undefined, // 账号
        this.form.email = undefined; // 邮箱
        this.form.creditCode = undefined; // 信用代码
        this.cancelSupDialog();
        return;
      }

      this.checkedSuppliers.forEach((item) => {
        // console.log('item=', item);
        this.form.supplierName = item.name;
        this.form.supplierIds.push(item.id);

        
        this.form.name = item.name; // 租户名称
        this.form.areaValue = []; // 区域数组
        if (item.districtCode && item.districtCode.length > 0) {
          this.form.areaValue = [item.provinceCode, item.cityCode, item.districtCode];
        } else if (item.cityCode && item.cityCode.length > 0) {
          this.form.areaValue = [item.provinceCode, item.cityCode];
        } else if (item.provinceCode && item.provinceCode.length > 0) {
          this.form.areaValue = [item.provinceCode];
        }
        this.form.provinceCode = item.provinceCode; // 省份编码
        this.form.cityCode = item.cityCode; // 城市编码
        this.form.districtCode = item.districtCode; // 区县编码
        this.form.address = item.address; // 详细地址
        // account: undefined, // 账号
        this.form.email = item.email; // 邮箱
        this.form.creditCode = item.creditCode; // 信用代码
      });
      this.cancelSupDialog();

     },

     /**
      * 选择关联供应商 点击取消
      */
     cancelSupDialog() {
      this.showSupplier = false;
      this.checkedSuppliers = [];
      // this.btnLoad = false;
      // this.$nextTick(() => {
      //   this.$refs.menu.setCheckedKeys([]);
      // });
     },

    /**
     * 获取行政区划数据
     */
     getDivisionTree() {
      getDivisionTree({name: ''}).then(res => {
        // console.log('res=', res);
        if (res.code === 200) {
          const list = res.data;
          if (list && list.length > 0) {
            this.areaList = list[0].children;
            // console.log('children=', list[0].children);
            // this.menuOptions = list[0].children;
          }
        }
      }).catch(err => {

      });
    },

    /**
     * 对日期控件做处理，今天以前的日期不可以选择
     * @param {*} time 
     */
    disabledDates(time) {
      let date = new Date();
      let currDate = this.$moment(date).format('YYYY-MM-DD') + ' 00:00:00';
      if (time.getTime() < new Date(currDate).getTime()) {
        return true;
      } else {
        return false;
      }

    },

    /**
     * 初始化租户级别
     */
    setupTenantLevels() {
      let level = this.$store.getters.level; // 当前用户的级别
      this.tenantLevels = [];
      const list = this.dict.type.sys_tenant_level;
      list.forEach((item) => {
        if (parseInt(item.value) <= level) {
          item = {...item, disabled:true};
        } else {
          item = {...item, disabled:false};
        }
        this.tenantLevels.push(item);
        // if (item.value !== '0') {
        //   this.tenantLevels.push(item);
        // }
      });
      // console.log('tenantLevels=', this.tenantLevels);
    },

    /**
     * 选择租户级别
     * @param {*} item 
     */
    changeTenantLevel(item) {
      this.form.parentId = undefined;
      this.form.templateId = undefined;

      this.parentListTenant(item);
      this.tenantTemplateOptions(item);
    },

    /**
     * 获取上级租户信息
     */
    parentListTenant(row) {
      if (this.form.level == '') {
        this.parentTenants = [];
        return;
      }
      this.isShowPresent = true;
      let level = this.$store.getters.level; // 当前用户的级别
      this.parentTenants = [];
      if (this.isAdd == false) {
        if (parseInt(this.form.level) - 1 < 0) {
          this.isShowPresent = false;
          return;
        }
        this.parentTenants.push({
          id: row.parentId,
          name: row.parentName
        });
        return;
      }
      
      const params = {
        level: parseInt(this.form.level) - 1 // 减1 表示本级别的上一级
      };
      
      parentListTenant(params).then(res => {
        this.parentTenants = res.data;
      });
    },

    /**
     * 获取权限模板下拉列表
     */
    tenantTemplateOptions(row) {
      if (this.form.level == '') {
        this.templateList = [];
        return;
      }
      this.templateList = [];
      if (this.isAdd == false) {
        this.templateList.push({
          id: row.templateId,
          name: row.templateName
        });
        return;        
      }
      const params = {
        level: this.form.level
      };
      tenantTemplateOptions(params).then(res => {
        // console.log('权限模板=', res);
        this.templateList = res.data;
      });
    },

    /**
     * 查询
     */
    handleQuery() {
      this.queryParams.pageNum = 1;
      // console.log('queryParams=', this.queryParams);
      if (this.queryParams.expireTime && this.queryParams.expireTime.length == 10) {
        this.queryParams.expireTime = this.queryParams.expireTime + ' 00:00:00';
      }
      this.getList();
    },

    /**
     * 重置
     */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /**
     * 获取列表
     */
    getList() {
      this.loading = true;
      // console.log('查询租户=', this.queryParams);
      listTenant(this.queryParams).then(res => {
        console.log('res=', res);
        this.dataList = res.data.records;
        this.total = Number(res.data.total);
        this.loading = false;
      }).catch(err => {
        // console.log('err=', err);
        this.loading = false;
      });
    },

    /**
     * 查询所有模板信息
     */
    initTemplates() {

    },

    /**
     * 是否激活字典翻译
     * @param {*} row 
     * @param {*} column 
     */
    activeFlagFormat(row, column) {
      let show = "";
      this.statusList.some((item) => {
        if (item.value === row.status) {
          show = item.label;
          return true;
        }
      });
      
      return show;
    },

    /**
     * 是否测试
     * @param {*} row 
     * @param {*} column 
     */
    testFlagFormat(row, column) {
      let show = "";
      if (row.isTest) {
        show = "是";
      } else {
        show = "否";
      }
      return show;
    },

    /**
     * 所属租户级别
     * @param {*} row 
     * @param {*} column 
     */
    levelFormat(row, column) {
      let show = '';
      this.dict.type.sys_tenant_level.some((item) => {
        // console.log('item=', item.value);
        // console.log('level=', row.level);
        if (row.level == item.value) {
          show = item.label;
          return true;
        }
      });
      return show;
    },

    /**
     * 选择级联
     * @param {*} value 
     */
    handleChangeArea(value) {
      console.log('区域=', value);
      console.log('areaValue=', this.form.areaValue);
    },

    /**
     * 生成客户数据
     */
    // generateCustomerData() {
    //   const data = [];
    //   const cities = ['上海', '北京', '广州', '深圳', '南京', '西安', '成都'];
    //   const pinyin = ['shanghai', 'beijing', 'guangzhou', 'shenzhen', 'nanjing', 'xian', 'chengdu'];
    //   cities.forEach((city, index) => {
    //     data.push({
    //       label: city,
    //       key: index,
    //       pinyin: pinyin[index]
    //     });
    //   });
    //   this.customerData = data;
    // },

    /**
     * 筛选数据
     * @param {*} query 
     * @param {*} item 
     */
    // filterCustomerData(query, item) {
    //   return item.pinyin.indexOf(query) > -1;
    // },

    /**
     * 新增或者修改
     */
    submitForm() {
      // console.log('areaValue=', this.form.areaValue);
      this.form.provinceCode = undefined;
      this.form.cityCode = undefined;
      this.form.districtCode = undefined;

      if (this.form.areaValue && this.form.areaValue.length == 3) {
        // provinceCode 省份编码 cityCode 城市编码 distictCode区县编码
        this.form.provinceCode = this.form.areaValue[0];
        this.form.cityCode = this.form.areaValue[1];
        this.form.districtCode = this.form.areaValue[2];// districtCode
      } else if (this.form.areaValue && this.form.areaValue.length == 2) {
        this.form.provinceCode = this.form.areaValue[0];
        this.form.cityCode = this.form.areaValue[1];
      } else if (this.form.areaValue && this.form.areaValue.length == 1) {
        this.form.provinceCode = this.form.areaValue[0];
      }
      
      // console.log('form=', this.form);
      if (this.form.expireTime && this.form.expireTime.length == 10) {
        this.form.expireTime = this.form.expireTime + ' 00:00:00';
      }
      if (this.form.name) {
        this.form.name = this.form.name.trim();
      }
      // this.disabled = true;
      this.$refs['form'].validate(valid => {
        // console.log('valid=', valid);
        if (!valid) {
          this.saveloading = false;
          return;
        }
        this.saveloading = true;
        if (this.form.id != undefined) {
          // 修改
          // console.log('修改');
          updateTenant(this.form).then(res => {
            // console.log('res=', res);
            if (res) {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                
                this.getList();
              }
              this.saveloading = false;
          }).catch(err => {
            this.saveloading = false;
          });
          // setTimeout(() => {
          //   this.disabled = false;
          // }, 2000);
        } else {
          // 新增
          // console.log('新增');
          addTenant(this.form).then(res => {
            // console.log('熙增=', res);
            if (res) {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }
            this.saveloading = false;
          }).catch(err => {
            this.saveloading = false;
          });
          // setTimeout(() => {
          //   this.disabled = false;
          // }, 2000);
        }
      });
    },

    /**
     * 取消
     */
    cancel() {
      this.reset();
      this.templateList = [];
      this.parentTenants = [];
      this.saveloading = false;
      this.open = false;
    },

    /**
     * 新增租户
     */
    handleAdd() {
      this.setupTenantLevels();
      // this.getCustomerOptionSelect(); // 客户信息
      this.isShowPresent = true;
      this.reset();
      this.open =  true;
      this.isAdd = true;
      this.title = "添加公司信息";

      // console.log('this.$store.getters.level=', this.$store.getters.level);
    },

    /**
     * 修改租户
     */
     handleUpdate(row) {
      this.setupTenantLevels();
      // this.getCustomerOptionSelect(); // 客户信息
      // this.reset();
      console.log('row=', row);
      let areaValue = [];
      if (this.form.districtCode && this.form.districtCode.length > 0) {
        // console.log('有区域=', this.form.districtCode);
        areaValue = [this.form.provinceCode, this.form.cityCode, this.form.districtCode];
      } else if (this.form.cityCode && this.form.cityCode.length > 0) {
        areaValue = [this.form.provinceCode, this.form.cityCode];
      } else if (this.form.provinceCode && this.form.provinceCode.length > 0) {
        areaValue = [this.form.provinceCode];
      }
      row = {
        ...row,
        areaValue: []
      }
      this.isAdd = false;
      this.form = JSON.parse(JSON.stringify(row));
      this.form.level = this.form.level + '';
      this.$set(this.form, 'customName', undefined);
      this.$set(this.form, 'supplierName', undefined);
      if (row.customerName && row.customerName.length) {
        this.form.customName = row.customerName[0];
      }
      if (row.supplierName && row.supplierName.length) {
        this.form.supplierName = row.supplierName[0];
      }
      
      if (this.form.districtCode && this.form.districtCode.length > 0) {
        // console.log('有区域=', this.form.districtCode);
        this.form.areaValue = [this.form.provinceCode, this.form.cityCode, this.form.districtCode];
      } else if (this.form.cityCode && this.form.cityCode.length > 0) {
        this.form.areaValue = [this.form.provinceCode, this.form.cityCode];
      } else if (this.form.provinceCode && this.form.provinceCode.length > 0) {
        this.form.areaValue = [this.form.provinceCode];
      }
      // this.resetForm("form");

      this.form.customIds = [];
      this.form.supplierIds = [];
      if(row.type == "SUPPLIER"){
        this.supplierList(); // 获取关联供应商列表
      }else{
        this.correlationCustomers(); // 获取关联客户列表
      }
      
      this.parentListTenant(row); // 获取上级租户信息
      this.tenantTemplateOptions(row); // 获取权限模板下拉列表
      this.open = true;
      
      this.title = '修改公司信息';
     },

     /**
      * 重置密码
      * @param {*} row 
      */
     handleResetPwd(row) {
      const h = this.$createElement;
      this.$confirm('', '重置密码', {
        message: h('p', null, [
          h('div', null, `是否给予租户【${row.name}】重置密码？`),
          h('div', null, '密码将重置为租户的初始密码。'),
        ]),
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        return resetPwdTenant({tenantId:Number(row.id)}).then((res) => {
          this.$modal.msgSuccess('重置成功');
        });
      }).catch(() => {

      });
     },

     /**
      * 导出租户
      */
      handleExport() {
        let params = this.queryParams;

        if (params.expireTime && params.expireTime.length == 10) {
          params.expireTime = params.expireTime + ' 00:00:00';
        }
        if (params.name) {
          params.name = params.name.trim();
        }

        delete params.pageNum;
        delete params.pageSize;
        this.$modal.confirm('是否确认导出所有租户信息数据项?', '警告', {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.downloadFile('system/tenant/export', {...params}, `tenant_${new Date().getTime()}.xlsx`);
        });
      },
      
      /**
       * 多选框选中数据
       * @param {*} selection 
       */
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id);
        this.single = selection.length!=1; // 是否单选
        this.multiple = !selection.length; // 是否多选
      },
  },
}
</script>

<style lang="scss" scoped>
  .customer-config {
    float: right;
    padding-bottom: 20px;
  }

  ::v-deep .el-dialog__body {
    padding-top: 0 !important;
  }



  .dialog-main {
  display: flex;
  flex-direction: row;
  border-top: 1px solid #EBEEF5;
  border-bottom: 1px solid #EBEEF5;

  .dialog-left {
    flex: 1;
    // background-color: red;
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #EBEEF5;
    .left-area {
      display: inline-block;
      width: 330px;
      // width:100%;
      height: 310px;
      margin-top: 5px;
      // border: 1px solid #e5e6e7;
      background: #FFFFFF none;
      // border-radius:4px;
      overflow: auto;
    }
  }
  .dialog-right {
    flex: 1;
    // background-color: orange;
    .right-top {
      margin-top: 37px;
      margin-bottom: 30px;
      margin-left: 10px;
      display: inline-block;
    }
    ::v-deep.el-table__header-wrapper {
      border: 0;
      height:0;
    }
    ::v-deep.el-table__cell {
      border: 0;
    }
    
    ::v-deep.el-table .cell {
      line-height: 28.5px;
    }
    .right-bottom {
      height: 312px;
      overflow: auto;
      // background-color: lightcoral;
      .table-column-area {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        flex
        .table-column-area-span {
          // flex: 3;
          height: 28.5px;
          font-size: 14px;
          font-weight: 400;
        }
        
        .table-column-area-btn {
          // flex: 1;
        }
      }
    }
  }
}

</style>